package com.xxl.job.admin.core.util;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Comparator;

public class StringUtil {
	
	/**
	 *  生成md5字符串
	 * @param inString
	 * @return
	 * @throws NoSuchAlgorithmException
	 */
	 public static String Md5Encode(String inString) throws NoSuchAlgorithmException {
		 String outString  = null;
		 byte[] buffer = inString.getBytes();
		 char hexDigist[] = {'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};
		 MessageDigest md = MessageDigest.getInstance("MD5");
		 md.update(buffer);
		 byte[] datas = md.digest(); 
		 char[] str = new char[2*16];
		 int k = 0;
		 for(int i=0;i<16;i++){
		      byte b   = datas[i];
		      str[k++] = hexDigist[b>>>4 & 0xf];
		      str[k++] = hexDigist[b & 0xf];
		 }
		 outString = new String(str);
		 return outString;
	 }
	 
	 /**
	  * 字符串数组用分号连接
	  * 
	  */
	 public static String join(String[] strarr, String lc )
	 {
		 String rtString = "";
		 if(strarr.length >0)
		 {
			 rtString += strarr[0]; 
			 for(int i=1;i<strarr.length;i++)
			 {
				 rtString += lc + strarr[i];
			 }
		 }
		 return rtString;
	 }
	
	 /**
	  * 获取Comparator
	  * 
	  * @return
	  */
	 public  Comparator<String> getComparator() {
		 MapKeyComparator mc = new MapKeyComparator();
		 return mc;
	 }
	 
	 private class MapKeyComparator implements Comparator<String>{  
		  public int compare(String str1, String str2) {  
		        return str1.compareTo(str2); 
		  }    
	 }
	 
}
